
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_jpf_core/core_enum.dart';
import 'package:flutter_jpf_core/page/base_state_page.dart';
import 'package:flutter_jpf_core/extension/map_extension.dart';
import 'package:flutter_jpf_core/util/data_util.dart';
import 'package:flutter_jpf_core/widgets/jpfbutton.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';

//调用：Navigator.of(context).pushNamed("/systemAddress",arguments: {"title":""});
class IndexPage  extends CommBasePage{

  @override
  CommBaseState getPageState() {
    return IndexPageState();
  }

}


class IndexPageState extends CommBaseState<IndexPage> {

  String title = "";
  int _currentPage = 1;
  EasyRefreshController _refreshController = EasyRefreshController();
  List<String> _lstData = new List<String>();

  ///////////////生命周期//////////////////////
  //初始化参数
  @override
  void initBaseParams() {
    // TODO: implement initBaseParams
  }

  //初始化页面数据，父类Widget build(BuildContext context)延时之后
  @override
  void initPageData() {
    Map data = getPageArguments();
    if(!DataUtil.isMapEmpty(data)){
      if(data["title"] != null){
        setState(() {
          title = data.strValue("title");
        });
      }
    }
    queryServiceData();
  }


  ///////////////接口相关//////////////////////
  @override
  void queryServiceData({ServiceType type = ServiceType.Default, bool showAnimail = true}) {

    //不是翻页初始化页面标记
    if(type != ServiceType.LoadMore){
      _currentPage = 1;
    }
    // TODO: implement queryServiceData
    if(type == ServiceType.Default && showAnimail){
      showProgressDialog(msg: "加载中...");
    }

    /*Presenter().request(_currentPage,(success, lst, message) {

      //关闭动画
      _refreshController.resetLoadState();
      _refreshController.finishRefresh(success: true);
      _refreshController.finishLoad(
          success: true,
          noMore: !success || lst.length<20);
      hideProgressDialog();
      if(success){
        _currentPage++;
        setState(() {
          if(type != ServiceType.LoadMore){
            _lstData.clear();
          }
          _lstData.addAll(lst);
        });
      }else{
        showToastTip(message);
      }
    });*/
  }


  ///////////////操作相关//////////////////////
  //提交数据
  void submitAction(){

  }


  ///////////////UI相关//////////////////////
  //页面UI
  @override
  Widget getViewsWidget() {
    hideProgressDialog();
    // TODO: implement getViewsWidget
    return Scaffold(
      // appBar: WidgetFatory.createMyAppBar(title, context,),
      /*persistentFooterButtons:  [
        Container(width: ScreenUtil.screenWidth,height: 45,child: Row(children: [Expanded(child: JPFButton("确定",(){
          //showToastTip("建设中，请稍等");
          submitAction();
        }),flex: 1,)],),)],*/
      body: SingleChildScrollView(
        child: EasyRefresh(
            controller: _refreshController,
            enableControlFinishRefresh: true,
            enableControlFinishLoad: true,
            header: MaterialHeader(),
            footer: MaterialFooter(),
            child: ListView.builder(
              itemCount: _lstData.length,
              itemBuilder: (BuildContext context, int index) {
                return Container(height: 45,);
              },
            ),
            onRefresh: () async {
              queryServiceData(type: ServiceType.Refresh);
            },
            onLoad: () async {
              queryServiceData(type: ServiceType.LoadMore);
            })
    ),);
  }

///////////////get/set//////////////////////


}